/*
 * FileName: ExecutorProxy.java
 * Author:   zzw
 * Date:     2018年05月05日
 * Description:
 */
package com.zzw.basic.classloader;

import java.lang.reflect.Method;

/**
 * 〈〉<br>
 * 〈〉
 *
 * @author zzw
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本]（可选）
 */
public class ExecutorProxy implements Executor {

    private String version;
    private MyUrlClassLoader classLoader;

    public ExecutorProxy(String version) {
        this.version = version;
        classLoader = new MyUrlClassLoader(version);
    }

    @Override
    public void execute(String name) {
        try {
            // Load ExecutorProxy class
            Class<?> executorClazz = classLoader.loadClass("Executor" + version.toUpperCase());

            Object executorInstance = executorClazz.newInstance();
            Method method = executorClazz.getMethod("execute", String.class);

            method.invoke(executorInstance, name);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Executor executor = new ExecutorProxy("v1");

        executor.execute("TOM");
    }
}
